package xyz.zhzby.cyzx.ucenter.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;
import xyz.zhzby.cyzx.ucenter.service.VerificationService;

/**
 * @author zby
 * @date 2021/12/17
 */
@RestController
@RequestMapping("/ucenter/code")
@ApiModel("获取验证码")
public class VerificationController {

    @Autowired
    private VerificationService verificationService;

    @ApiOperation("获取邮件验证码,传参为空说明已经绑定邮箱，直接取就行")
    @GetMapping("/mail")
    public RestResponse<String> sendMailCode(@RequestParam("email") String email) {
        return verificationService.sendMailCode(email);
    }

    @ApiOperation("验证邮箱验证码试是否正确")
    @GetMapping("/mail/code")
    public RestResponse<String> verifyEmailCode(@RequestParam("code") String code) {
        return verificationService.verifyEmailCode(code);
    }

    @ApiOperation("获取短信验证码,传参为空说明已经绑定手机号，直接取就行")
    @GetMapping("/phone")
    public RestResponse<String> sendSmsCode(@RequestParam("phone") String phone) {
        return verificationService.sendSmsCode(phone);
    }

    @ApiOperation("验证手机验证码试是否正确")
    @GetMapping("/phone/code")
    public RestResponse<String> verifySmsCode(@RequestParam("code") String code) {
        return verificationService.verifySmsCode(code);
    }

}
